#ifndef COMMAND_PARSE_H
#define COMMAND_PARSE_H

#include "string.h"
#include "includes.h"

#define MSG_CMD_TYTES   20      //串口数据解析成函数名的最大长度
#define MSG_ARG_LEN     32      //协议中数据的最大长度
#define MSG_CMD_LEN     3       //协议中命令的最大长度
#define MSG_MAX_ARGS    3      //一个协议帧包含的命令数量,如cal poi pow
#define MSG_COUNT       (sizeof(s_cmd_buf)/sizeof(s_cmd_buf[0]))



typedef struct
{
    unsigned  char  cmd[3][4];        //命令
    unsigned  char  data[2][36];      //数据
} Cmd_Info_Type;


	
extern unsigned char msg_idn_fun(Cmd_Info_Type x);
extern unsigned char msg_ver_fun(Cmd_Info_Type x);
extern unsigned char msg_rst_fun(Cmd_Info_Type x);
extern unsigned char msg_key_set_fun(Cmd_Info_Type x);

extern unsigned char msg_sys_upgrade_fun(Cmd_Info_Type x);
extern unsigned char msg_set_wavelength_fun(Cmd_Info_Type x);
extern unsigned char msg_set_power_fun(Cmd_Info_Type x);
extern unsigned char msg_set_linear_reset_fun(Cmd_Info_Type x);  //清除线性
extern unsigned char msg_set_coeff_reset_fun(Cmd_Info_Type x);
extern unsigned char msg_set_time_fun(Cmd_Info_Type x);
extern unsigned char msg_set_threshold_name_fun(Cmd_Info_Type x);
extern unsigned char msg_set_threshold_1310_fun(Cmd_Info_Type x);
extern unsigned char msg_set_threshold_1490_fun(Cmd_Info_Type x);
extern unsigned char msg_set_threshold_1550_fun(Cmd_Info_Type x);
#if FHP3P05
	extern unsigned char msg_set_threshold_1270_fun(Cmd_Info_Type x);
	extern unsigned char msg_set_threshold_1577_fun(Cmd_Info_Type x);
#endif 
extern unsigned char msg_set_cal_reset_fun(Cmd_Info_Type x);

extern unsigned char msg_get_wavelength_fun(Cmd_Info_Type x);
extern unsigned char msg_get_power_fun(Cmd_Info_Type x);
extern unsigned char msg_get_history_fun(Cmd_Info_Type x);
extern unsigned char msg_get_vol_fun(Cmd_Info_Type x);
extern unsigned char msg_get_threshold_name_fun(Cmd_Info_Type x);
extern unsigned char msg_get_threshold_1310_fun(Cmd_Info_Type x);
extern unsigned char msg_get_threshold_1490_fun(Cmd_Info_Type x);
extern unsigned char msg_get_threshold_1550_fun(Cmd_Info_Type x);
#if FHP3P05
	extern unsigned char msg_get_threshold_1270_fun(Cmd_Info_Type x);
	extern unsigned char msg_get_threshold_1577_fun(Cmd_Info_Type x);
#endif 
extern unsigned char msg_set_history_reset_fun(Cmd_Info_Type x);
//extern unsigned char msg_get_group_wave_threshold_fun(Cmd_Info_Type x);
extern unsigned char msg_get_wave_offset_fun(Cmd_Info_Type x);

extern unsigned char msg_cal_start_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_stop_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_save_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_level_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_point_power_fun(Cmd_Info_Type x);
//extern unsigned char msg_cal_wav_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_iso_1490_1550_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_iso_1550_1490_fun(Cmd_Info_Type x);
//extern unsigned char msg_cal_reset_fun(Cmd_Info_Type x);
extern unsigned char msg_cal_wave_offset_fun(Cmd_Info_Type x);

extern unsigned char msg_sys_screen_fun(Cmd_Info_Type x);
extern unsigned char msg_set_idn_fun(Cmd_Info_Type x);
extern unsigned char msg_set_btname_fun(Cmd_Info_Type x);
	
	// 需要和下方对应
static const char *const s_cmd_buf[][MSG_MAX_ARGS] =
{
    {"idn", "\0", "\0"},
    {"ver", "\0", "\0"},
    {"rst", "\0", "\0"},
		{"key", "set", "\0"},
		
    {"set", "wav", "\0"},
    {"set", "pow", "\0"},
    {"set", "lin", "res"},
    {"set", "coe", "res"},
    {"set", "tim", "\0"},
    {"set", "idn", "\0"},
		
		{"set", "thr", "nam"},
		{"set", "thr", "131"},
		{"set", "thr", "149"},
		{"set", "thr", "155"},
#if FHP3P05
		{"set", "thr", "127"},
		{"set", "thr", "157"},
#endif
		{"set", "cal", "res"},
		{"set", "his", "res"},
//  {"set", "btn", "\0"},
//  {"get", "wav", "\0"},
    {"get", "pow", "\0"},
    {"get", "his", "\0"},
		{"get", "vol", "\0"},
		
		{"get", "thr", "nam"},
		{"get", "thr", "131"},
		{"get", "thr", "149"},
		{"get", "thr", "155"},
#if FHP3P05
		{"get", "thr", "127"},
		{"get", "thr", "157"},
#endif
		{"get", "wav", "off"},
		
    {"cal", "poi", "pow"},
    {"cal", "sta", "\0"},
    {"cal", "sto", "\0"},
    {"cal", "sav", "\0"},
    {"cal", "lev", "\0"},
		{"cal","iso","\0"},
	//	{"cal","res","\0"},
		{"cal","wav","off"},
		
    {"upg", "\0", "\0"},
 //   {"sys", "scr", "\0"},
};


/*命令处理函数*/
static unsigned  char ( * const cmd_deal_port[MSG_COUNT])(Cmd_Info_Type x) =
{
      msg_idn_fun,
      msg_ver_fun,
      msg_rst_fun,
			msg_key_set_fun,
	
  		msg_set_wavelength_fun,
			msg_set_power_fun,
			msg_set_linear_reset_fun,
			msg_set_coeff_reset_fun,
			msg_set_time_fun,
			msg_set_idn_fun,
	
	    msg_set_threshold_name_fun,
			msg_set_threshold_1310_fun,
			msg_set_threshold_1490_fun,
			msg_set_threshold_1550_fun,
#if FHP3P05
			msg_set_threshold_1270_fun,
			msg_set_threshold_1577_fun,
#endif
			msg_set_cal_reset_fun,
			msg_set_history_reset_fun,
//		msg_set_btname_fun,
	//	msg_get_wavelength_fun,
			msg_get_power_fun,
			msg_get_history_fun,
			msg_get_vol_fun,
			msg_get_threshold_name_fun,
			msg_get_threshold_1310_fun,
			msg_get_threshold_1490_fun,
			msg_get_threshold_1550_fun,
#if FHP3P05
			msg_get_threshold_1270_fun,
			msg_get_threshold_1577_fun,
#endif
			msg_get_wave_offset_fun,
	
			msg_cal_point_power_fun,
			msg_cal_start_fun,
			msg_cal_stop_fun,
			msg_cal_save_fun,
			msg_cal_level_fun,
			msg_cal_iso_1490_1550_fun,
	//		msg_cal_reset_fun,
			msg_cal_wave_offset_fun,
	//		msg_cal_wav_fun
    msg_sys_upgrade_fun,
 //   msg_sys_screen_fun,
};


// 字符串解析方法 1
int communicate_parse(const char *data);




#endif
